package com.iron.consumer.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.iron.consumer.entity.TxA;
import com.iron.consumer.entity.TxB;
import com.iron.consumer.feign.IronProviderFeign;
import com.iron.consumer.mapper.TxAMapper;
import com.iron.consumer.service.TxAService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author yt
 * @date 2019-07-16 17:01:09
 */
@Slf4j
@Service
@AllArgsConstructor
public class TxAServiceImpl extends ServiceImpl<TxAMapper, TxA> implements TxAService {

    private final IronProviderFeign ironProviderFeign;

//    @LcnTransaction
    @Transactional(readOnly = false, rollbackFor = Exception.class)
    @Override
    public boolean testSaveTxATxB(TxA txA, TxB txB) {
        log.info("----------- 调用远程 iron-sfm 服务 -----------");
        ironProviderFeign.save(txB);
        log.info("----------- 执行本地 iron-consumer 服务 -----------");
        int a = 1 / 0;
        return super.save(txA);
    }

    @Transactional(readOnly = false, rollbackFor = Exception.class)
    @Override
    public void add(TxA txA) {
        super.save(txA);
    }

    @Override
    public void addTxA(TxA txA) {
        add(txA);
        int a = 1 / 0;
    }
}
